# Project: From Home Base to Swing States: The Evolution of Digital Advertising 
#          Strategies during the 2020 US Presidential Primary
# Authors: NaLette Brodnax and Piotr Sapiezynski

library(tidyverse)
library(stargazer)

ads <- read_csv('replication_data_aggregate.csv') 

fit1 <- lm(budget_frac_per_resident ~ is_home + swing + feb + march, 
           data = ads)

fit2 <- lm(budget_frac_per_resident ~ is_home + is_ia + is_nh + 
             factor(state) - 1, 
           data = ads)

fit3 <- lm(budget_frac_per_resident ~ is_home + is_ia + is_nh + 
             factor(state) + factor(candidate) - 1, 
           data = ads)

fit4 <- lm(budget_frac_per_resident ~ is_home + swing + feb + march + 
             caucus + pledged_delegates + median_income_k + dem_turnout_pts,  
           data = ads)

table4 <- stargazer(fit1, fit4, fit2, fit3, type='text', out.header=FALSE, 
          covariate.labels = c('Home', 'Swing', 'February Primary',
                               'Super Tuesday Primary', 'Caucus', 'Delegates',
                               'Median Income', 'Democratic Turnout',
                               'Iowa', 'New Hampshire', 'Intercept'),
          keep.stat = c('n'), omit=c('factor*'), dep.var.caption = '', 
          dep.var.labels.include = FALSE, no.space = TRUE, align = TRUE,
          title = 'Relative proportion of advertising budget', 
          add.lines = list(c('State Fixed Effects', 'No', 'No', 'Yes', 'Yes'),
                           c('Candidate Fixed Effects', 'No', 'No', 'No', 'Yes')))
